package 剑指Offer1;

import java.util.PriorityQueue;
import java.util.Queue;
/*
    comparator比较器的compare方法中，
    o1和o2两个参数:o1是新加的那个参数，o2是之前已经添加的
 */
public class _36把数组排成最小的数 {
    public static String minNumber(int[] nums) {
        if(nums == null || nums.length == 0) return null;
        //排序规则按照 两个字符串相加 小的放在上面
        Queue<String> minHeap = new PriorityQueue<>((o1,o2)->(o1+o2).compareTo(o2+o1));
        for (int num : nums) {
            minHeap.offer(""+num);
        }
        StringBuilder sb = new StringBuilder();
        while(!minHeap.isEmpty()){
            sb.append(minHeap.poll());
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        //System.out.println( minNumber(new int[]{3,30,34,5,9}));
        //System.out.println("303".compareTo("330"));
    }
}
